package com.zhenwgang.listen_books.servlet.publish;

import com.zhenwgang.listen_books.repository.AlbumRepo;
import com.zhenwgang.listen_books.view_object.ResultView;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Violet
 * @date 2022/07/21 21:43
 **/
@WebServlet("/album-list.json")
public class AlbumListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AlbumRepo albumRepo = new AlbumRepo();
        ResultView resultView = new ResultView();
        albumRepo.selectBySameUid(resultView);

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(resultView);

        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json");
        resp.getWriter().println(json);
    }
}